package com.springCrud.simpleCrud.service;


import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.springCrud.simpleCrud.dao.GenericDao;
import com.springCrud.simpleCrud.entity.SimpleCrud;
import com.springCrud.simpleCrud.util.Constraint;
import com.springCrud.simpleCrud.util.OrderMap;
import com.springCrud.simpleCrud.util.SearchResult;


@Service("SimpleCrudService") @Transactional
public class SimpleCrudServiceImpl implements SimpleCrudService {
	
	protected final Log logger = LogFactory.getLog(this.getClass());
	
	@Autowired private SessionFactory sessionFactory;
	@Autowired private GenericDao genericDao;
	
	public SearchResult searchSimpleCrud(Constraint constraint, OrderMap orderMap,
            boolean isUsingPaging, int offset, int pageSize) {
		
        SearchResult searchResult = genericDao.searchHQL("simpleCrud", "SimpleCrud simpleCrud", constraint, orderMap, isUsingPaging, offset, pageSize);
        
        return searchResult;
    }
	
	public SimpleCrud findSimpleCrudById(Long id){
		
    	SimpleCrud gems= (SimpleCrud) sessionFactory.getCurrentSession().get(SimpleCrud.class, id);
    	
		return gems;
    }
	
	public void save(SimpleCrud simpleCrud) {
		sessionFactory.getCurrentSession().saveOrUpdate(simpleCrud);
	}
}
